package warehouse;

import java.util.HashMap;

import java.util.TreeSet;

/**
 * ItemList class contains the HashMap collection we use for storing the items
 * with their id as a key value
 * 
 * @author Apeiranthitis, Grassos, Moschos
 * 
 */
public class ItemList implements Observer {
	// Storage for an arbitrary number of details.
	private HashMap<String, Item> itemList;

	/**
	 * ItemList class constructor Initializes a new HashMap collection
	 * consisting of <String,Item> pairs
	 */
	public ItemList() {
		itemList = new HashMap<String, Item>();
	
		
	}

	/**
	 * Add a new set of details to the list
	 * 
	 * @param details
	 *            The item object details
	 */
	public void addDetails(String id, Item details) {
		itemList.put(id, details);
	}

	/**
	 * Checks if the HashMap collection is not empty
	 * 
	 * @return boolean
	 */
	public boolean hasItem() {
		return itemList.size() != 0;
	}

	/**
	 * Gets next item from the HashMap collection
	 * 
	 * @return
	 */
	public Mouse getNextItem() {
		Mouse mouse = null;
		Item item = itemList.remove(0);
		if (item instanceof Mouse) {
			mouse = (Mouse) item;
			
		}

		return mouse;

	}

	/**
	 * Iterates over the HashMap collection and prints all values within it we
	 * used it in the beginning for checking but not using this method now
	 */
	public String printItems() {

		TreeSet<String> keys = new TreeSet<String>(itemList.keySet());

		String f = "";
		for (String key : keys) {

			Item value = itemList.get(key);
			f += value;

		}

		return f;

	}

	/**
	 * Searches for an Item, while provided with an ID and returns the item
	 * 
	 * @param id
	 * @return Item
	 */
	public Item getItembyId(String id) {
		Item m = itemList.get(id);
		return m;
	}

	/**
	 * Checks whether an ID already exists in our HashMap collection
	 * 
	 * @param id
	 *            the item id of an item
	 * @return true or false
	 */
	public boolean keyExists(String id) {
		boolean blnExists = itemList.containsKey(id);
		if (blnExists)
			System.out
					.println("Item id " + id + " already exists in Warehouse");
		return blnExists;
	}

	public void update() {
		System.out.println("ITEM CHANGED");

	}
}
